use std::cmp::Ordering;
use std::io;
use rand::Rng;

pub fn guessing_game() {
    println!("Guessing the number");

    let secret_number = rand::thread_rng().gen_range(1..100);
    println!("The secret_num is: {secret_number}");

    loop {
        println!("Please input a number:");
        let mut guess = String::new();

        io::stdin().read_line(&mut guess)
            .expect("Failed to read line");

        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };
        println!("You guessed: {guess}");
        match guess.cmp(&secret_number) {
            Ordering::Less => { println!("Too Small") }
            Ordering::Equal => {
                println!("You Win!!!");
                break;
            }
            Ordering::Greater => { println!("Too Big") }
        }
    }
}